#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main()
{
    int x1[1010],y1[1010],x2[1010],y2[1010],r[1010],g[1010],b[1010],n,m,i=0,x,y;
    while(cin>>n>>m){
        if(n==0&&m==0) break;
        i++;
        int j,l;
        bool flag;
        for( j=0;j<n;j++)
        {
           cin>>x1[j]>>y1[j]>>x2[j]>>y2[j]>>r[j]>>g[j]>>b[j];
        }
       // cout<<"Case "<<i<<":"<<endl;
        int a[1010],d[1010],c[1010],h=0;
        for(j=0;j<m;j++)
        {
          flag=false; 
          cin>>x>>y;
          for(l=n-1;l>=0;l--)
        { 
             if( x<=x2[l]&&x>=x1[l]&&y<=y2[l]&&y>=y1[l] )  {a[j]=r[l];d[j]=g[l];c[j]=b[l];flag=true;break;}
        }          
          if(!flag)  {a[j]=255;d[j]=255;c[j]=255;} 
        }
        cout<<"Case "<<i<<":"<<endl; 
        for(j=0;j<m;j++)
         cout<<a[j]<<" "<<d[j]<<" "<<c[j]<<endl;
        cout<<endl;
    } 
    return 0;
}
